<?php
require '..\Common\values.php';
require '..\Common\database.php';

$mins=0;
if ($_POST[date]=='')
{

    $_POST[date]=$date;
}

$body = '<head>
<STYLE TYPE="text/css">
td
{
border : 1px solid #000000 ;
}
</STYLE>
</head>
<body><center>VHS Stats for '.$date.'<BR><br><table cellspacing=0 cellpadding=3 ><tr bgcolor="#64Bfff">';

$query='SELECT * FROM tbldashboard2';
$result1 = mysql_query($query);
while($row1 = mysql_fetch_array($result1))
{
 $body .= '<td>'.$row1[Select].'</td>';
}
$body .= '<td>Not Assigned</td>';
$result = mysql_query("SELECT * FROM tblUsers WHERE Username!='systemadmin'");
while($row = mysql_fetch_array($result))
{
$body .= '<td>'.$row[Name].'</td>';
}
$body .= '<td>All Open</td><td>1st Line</td><td>2nd Line</td></tr><tr>';

$query='SELECT * FROM tbldashboard2';
$result1 = mysql_query($query);
while($row1 = mysql_fetch_array($result1))
{
switch($row1[Closed])
    {
case(Open);
    $row1[Closed]='';
    break;
case(Closed);
    $row1[Closed]='checked';
    break;
    }

mysql_query("SELECT * FROM tblJobs WHERE status LIKE '$row1[Status]' AND LogNumber LIKE '$row1[LogNumber]' AND Requestor LIKE '$row1[Requestor]' AND Subject LIKE '$row1[Subject]' AND Proirty LIKE '$row1[Proirty]' AND Closed LIKE '$row1[Closed]' AND Assigned LIKE '$row1[Assigned]' AND Line LIKE '$row1[Line]' AND Project LIKE '$row1[Project]' AND Due LIKE '$row1[Due]' AND Branch LIKE '$row1[Branch]' AND Department LIKE '$row1[Department]' AND `Private` LIKE '$row1[Private]'");

    $body .= "<td><b>".mysql_affected_rows()."</b></td>";
}

mysql_query("Select * From tblJobs where Assigned='Not Assigned' And Closed=' ' ");
$body .= "<td><b>".mysql_affected_rows()."</b></td>";

$result = mysql_query("SELECT * FROM tblUsers WHERE Username!='systemadmin'");
while($row = mysql_fetch_array($result))
{
mysql_query("Select * From tblJobs where Assigned='$row[Name]' And Closed=' ' AND Project = 'Helpdesk' ");
$body .= "<td><b>".mysql_affected_rows()."</b></td>";
}
mysql_query("Select * From tblJobs where Closed=' ' AND Project Like 'Helpdesk' ");
$body .= "<td><b>".mysql_affected_rows()."</b></td>";

mysql_query("Select * From tblJobs where Closed=' ' AND Line='1' AND Project Like 'Helpdesk' ");
$body .= "<td><b>".mysql_affected_rows()."</b></td>";

mysql_query("Select * From tblJobs where Closed=' ' AND Line='2'AND Project Like 'Helpdesk' ");
$body .= "<td><b>".mysql_affected_rows()."</b></td>";

$body .= '</tr></table>';
$body .= '<br>All Open<table width="500"><tr bgcolor="#64Bfff"><td></td><td>08:00</td><td>09:00</td><td>10:00</td><td>11:00</td><td>12:00</td><td>13:00</td><td>14:00</td><td>15:00</td><td>16:00</td><td>17:00</td><td>18:00</td></tr>';
$body .= '<tr><td>Today</td>';
$hour='8';

while($hour<19)
{
if($hour<10)
{
$time1='0'.$hour.':00';
}
else
{
    $time1=$hour.':00';
}
$query=mysql_query("SELECT * FROM tblhstats WHERE Date='$date' AND Time='$time1'");
if(mysql_affected_rows()>0)
{
while($row = mysql_fetch_array($query))
{
$body .= '<td>'.$row['Allopen'].'</td>';
}

}
else
{
$body .= '<td>0</td>';

}
$hour=$hour+1;
}

$body .= '<tr><td>Yesterday</td>';
$hour='8';

while($hour<19)
{
if($hour<10)
{
$time1='0'.$hour.':00';
}
else
{
    $time1=$hour.':00';
}
$query=mysql_query("SELECT * FROM tblhstats WHERE Date='$yesterday' AND Time='$time1'");
if(mysql_affected_rows()>0)
{
while($row = mysql_fetch_array($query))
{
$body .= '<td>'.$row['Allopen'].'</td>';
}

}
else
{
$body .= '<td>0</td>';

}
$hour=$hour+1;
}




$body .= '</table>';

$body .= '<table><tr><td><table>
<tr bgcolor="#64Bfff"><td><b>Total</td><td><b>Today</td><td><b>Yesterday</td><td><b>MTD</td><td><b>Last Month</td><td><b>YTD</td></tr>
<tr><td>Job created</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$yesterday'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$mtd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Date LIKE '$ytd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';

$body .= '<tr><td>Jobs closed</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$yesterday'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$mtd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Date LIKE '$ytd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';

$body .= '<tr bgcolor="#64Bfff"><td><b>Created</td>';
$result = mysql_query("SELECT * FROM tblUsers WHERE Username!='systemadmin'");
while($row = mysql_fetch_array($result))
{

$body .= '<tr><td>'.$row[Name].'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND operator LIKE '$row[Name]' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$yesterday'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$mtd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$ytd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td></tr>';
}
$body .= '<td>Public</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$yesterday'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$mtd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Created New Job' AND Operator LIKE 'public' AND Date LIKE '$ytd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';



$body .= '<tr bgcolor="#64Bfff"><td><b>Closed</td>';
$result = mysql_query("SELECT * FROM tblUsers WHERE Username!='systemadmin'");
while($row = mysql_fetch_array($result))
{

$body .= '<tr><td>'.$row[Name].'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$_POST[date]'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$yesterday'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$mtd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$lastmonth'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td>';
mysql_query("SELECT * FROM tblEvents WHERE description = 'Closed Job' AND Operator LIKE '$row[Name]' AND Date LIKE '$ytd'  ORDER BY `key` ");
$body .= '<td>'.mysql_affected_rows().'</td></tr>';
}


$body .='</tr></table></td>';

$body .='<td valign="top"><table><tr bgcolor="#64Bfff"><td>Operator</td><td>Minutes worked</td></tr>';
$query=mysql_query("SELECT * FROM tblUsers WHERE Username!='systemadmin'");
while($row = mysql_fetch_array($query))
{
$body .='<tr><td>'.$row[Name].'</td>';
$query1=mysql_query("SELECT * FROM tblEvents WHERE Date='$date' AND Operator='$row[Name]'");
while($row = mysql_fetch_array($query1))
{
$mins=$mins+$row[TimeS];
}
$body .= '<td>'.$mins.'</td></tr>';
$mins=0;
}

$body .= '</table></td></tr>


    <tr class="noborder"><td class="noborder">';
    $body .= '<table cellpadding="5" class="noborder">
    <tr class="noborder"><td>Current jobs</td>';
    mysql_query("Select * FROM tbljobs");
    $body .= '<td>'.mysql_affected_rows().'</td></tr>';
    $body .= '<tr class="noborder"><td>Archived jobs</td>';
    mysql_query("Select * FROM tbljobsarchive");
    $body .= '<td>'.mysql_affected_rows().'</td></tr>';

    $body .= '<tr class="noborder"><td>Current solutions</td>';
    mysql_query("Select * FROM tblsolutions");
    $body .= '<td>'.mysql_affected_rows().'</td></tr>';
    $body .= '<tr class="noborder"><td>Archived solutions</td>';
    mysql_query("Select * FROM tblsolutionsarchive");
    $body .= '<td>'.mysql_affected_rows().'</td></tr>';




    $body .= '</table></td></table></td></tr></table>';



ini_set('SMTP', '192.168.14.140');
ini_set('sendmail_from', 'vhs@vospers.com');
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0;' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1;' . "\n";
// Additional headers
$headers .= 'To: svb@vospers.com;' . "\n";
$headers .= 'From:Helpdesk System <vhs@vospers.com>;' . "";
$Name = "Helpdesk System"; //senders name
$email = "VHS@vospers.com"; //senders e-mail adress
$recipient='svb@vospers.com';
$subject='VHS Stats';
mail($recipient, $subject, $body, $headers);
?>
